package com.ls.blog.utils;

import com.alibaba.fastjson.JSON;
import com.ls.blog.DTO.UserDetailsDTO;
import com.ls.blog.entity.UserInfo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


/**
 * 用户工具类
 *
 * @author yezhiqiu
 * @date 2021/08/10
 */
@Component
public class UserUtils {

    @Autowired
    private RedisUtil redisUtil;
    /**
     * 获取当前登录用户
     * @return 用户登录信息
     */
    public UserInfo getLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("Authorization");

//        redisUtil.hget("token", token)
//        return userInfo;
        return null;

    }

    /**
     * 移除当前登录的用户
     */
    public void removeLoginUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("Authorization");
        redisUtil.hdel("token",token);

    }

}
